package com.kaibes.admin.log;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.kaibes.core.base.annotation.Description;
import com.kaibes.module.log.ApiLogService;
import com.kaibes.web.admin.AdminController;
import com.kaibes.web.api.ApiLink;

@AdminController
@RequestMapping("/admin/log")
public class ApiLogController {

    @Autowired
    private ApiLogService apiLogService;

    @GetMapping("api")
    @ApiLink("API日志")
    public String log(Model model, @RequestParam(defaultValue = "25") @Description("每页长度") int size,
            @RequestParam(defaultValue = "1") @Description("当前页数") int page,
            @RequestParam(defaultValue = "") @Description("搜索内容") String search) {
        if (search.isEmpty()) {
            model.addAttribute("logPage", apiLogService.page(page, size));
        } else {
            try {
                apiLogService.pageBySearch(page, size, search);
            } catch (Exception e) {
                e.printStackTrace();
            }
            model.addAttribute("logPage", apiLogService.pageBySearch(page, size, search));
        }
        return "api-log";
    }

}
